package com.von.nhcf.mvc.config;

import com.von.nhcf.entity.Admin;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.List;

/**
 * 将Admin包装成SpringSecurity的User类型
 * @author von
 */
public class AdminToSecurityUser extends User {
    private Admin originalAdmin;

    public AdminToSecurityUser(Admin originalAdmin, List<GrantedAuthority> authorities) {
        // 调用父类构造器
        super(originalAdmin.getLoginAcct(), originalAdmin.getUserPswd(), authorities);
        // 给本类的 this.originalAdmin 赋值
        this.originalAdmin = originalAdmin;
        // 擦除原始admin对象的密码
        this.originalAdmin.setUserPswd(null);
    }

    // 对外提供获取originalAdmin的方法
    public Admin getOriginalAdmin() {
        return originalAdmin;
    }
}
